package com.qiguliuxing.dts.job.config;

import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.qiguliuxing.dts.job.base.LiteJobDefinition;
import com.qiguliuxing.dts.job.listener.JobListener;
import com.qiguliuxing.dts.job.task.SeckillSubMsgJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 秒杀消息通知job 配置
 *
 * @author 1197673878@qq.com
 * @since 2020年9月9日 上午11:47:50
 */
@Configuration
public class SeckillSubMsgJobConfig {

	@Value("${seckill.sub.msg.job.cron}")
	private String cron;
	
	@Value("${seckill.sub.msg.job.shard.cnt}")
	private int shardingTotalCount;
	
	@Value("${seckill.sub.msg.job.shard.item}")
	private String shardingItemParameters;
	
	@Value("${seckill.sub.msg.job.params}")
	private String jobParameters;

	@Autowired
	private ZookeeperRegistryCenter regCenter;

	@Bean(initMethod = "init")
	public JobScheduler seckillSubMsgJobScheduler(final SeckillSubMsgJob seckillSubMsgJob) {
		JobListener jobListener = new JobListener();
		return new SpringJobScheduler(seckillSubMsgJob, regCenter, LiteJobDefinition.getLiteJobConfiguration(seckillSubMsgJob.getClass(), cron,
				shardingTotalCount, shardingItemParameters, jobParameters), jobListener);
	}
}